/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DatosEcoestresPanel.java
 *
 * Created on 17/01/2011, 17:20:58
 */

package presentacion.examen;

import hibernate.objeto.ElectrofisiologicoEstudioCardiologia;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JDialog;
import logica.CapaLogica;
import presentacion.CapaPresentacion;
import presentacion.utilidad.maquetado.Fuente;

/**
 *
 * @author Gonzalo
 */
public class DatosElectrofisiologicoPanel extends javax.swing.JPanel {

    /** Creates new form DatosEcoestresPanel */
    public DatosElectrofisiologicoPanel() {
        initComponents();
        setearEventosQueCapturanTeclaEnterYEscape();
    }

    /**
     * Setea datos de la ventana.
     *
     */
    public void personalizarJDialog(ElectrofisiologicoEstudioCardiologia 
            electrofisiologicoEstudioCardiologia) {
        this.electrofisiologicoEstudioCardiologia =
                electrofisiologicoEstudioCardiologia;
            exhibirDatosEnPantalla();
            if(CapaPresentacion.modoVisualizacion) {
                inhabilitarCampos();
            }
    }

    /**
     * Permite visualizar los detalles de la evolución.
     *
     */
    private void exhibirDatosEnPantalla() {
        conclusionesElectrofisiologico.setText(
                electrofisiologicoEstudioCardiologia.
                getConclusionElectrofisiologicoEstudioCardiologia());
        conclusionesElectrofisiologico.setCaretPosition(0);
    }

    /**
     * Pone en false la propiedad enabled de todos los campos de ingreso.
     *
     */
    private void inhabilitarCampos() {
        conclusionesElectrofisiologico.setEnabled(false);
    }

    /**
     * Recopila los datos del panel para colocarlos dentro del arreglo.
     *
     * @param datosEstudioCardiologia El arreglo a cargar
     */
    public void recopilarDatos(Object[] datosEstudioCardiologia) {

        datosEstudioCardiologia[CapaLogica.
                ESTUDIO_CARDIOLOGIA_ELECTROFISIOLOGICO_CONCLUSIONES] =
                conclusionesElectrofisiologico.getText();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        conclusionesElectrofisiologicoScrollPane = new javax.swing.JScrollPane();
        conclusionesElectrofisiologico = new javax.swing.JTextArea();
        textoConclusionesElectrofisiologico = new javax.swing.JLabel();

        conclusionesElectrofisiologicoScrollPane.setPreferredSize(new java.awt.Dimension(243, 80));

        conclusionesElectrofisiologico.setColumns(20);
        conclusionesElectrofisiologico.setFont(Fuente.FUENTE_TEXTFIELD);
        conclusionesElectrofisiologico.setRows(4);
        conclusionesElectrofisiologicoScrollPane.setViewportView(conclusionesElectrofisiologico);

        textoConclusionesElectrofisiologico.setFont(Fuente.FUENTE_TEXTFIELD);
        textoConclusionesElectrofisiologico.setText("Conclusiones");
        textoConclusionesElectrofisiologico.setPreferredSize(new java.awt.Dimension(102, 20));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(textoConclusionesElectrofisiologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(conclusionesElectrofisiologicoScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textoConclusionesElectrofisiologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(conclusionesElectrofisiologicoScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Setea en cada componente del JDialog los eventos que capturarán la tecla
     * enter y escape.
     */
    private void setearEventosQueCapturanTeclaEnterYEscape() {
        //Declaración del evento a capturar
        KeyListener keyListenerEscape = new KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    cerrarVentana();
                }
            }
        };

        //Setear eventos
        conclusionesElectrofisiologico.addKeyListener(keyListenerEscape);
    }

    private void cerrarVentana() {
        JDialog jdialog = (JDialog)
                this.getParent().getParent().getParent().getParent().
                getParent().getParent().getParent().getParent().
                getParent().getParent().getParent().getParent().getParent();
        jdialog.dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea conclusionesElectrofisiologico;
    private javax.swing.JScrollPane conclusionesElectrofisiologicoScrollPane;
    private javax.swing.JLabel textoConclusionesElectrofisiologico;
    // End of variables declaration//GEN-END:variables
    private ElectrofisiologicoEstudioCardiologia
            electrofisiologicoEstudioCardiologia;
}
